package io操作;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;

public class 序列化流 {
    public static void 序列化流() throws Exception {
        Student student = new Student();
        student.setId(1);
        student.setName("巧克力");
        student.setScore(65L);
        ObjectOutputStream objectOutputStream = new ObjectOutputStream(new FileOutputStream("序列化流.txt",true));
        objectOutputStream.writeObject(student);
        objectOutputStream.close();
    }

    public static void 反序列化流() throws Exception {
        ObjectInputStream objectInputStream = new ObjectInputStream(new FileInputStream("序列化流.txt"));
        Student student = (Student) objectInputStream.readObject();
        System.out.println(student);
    }

    public static void main(String[] args) throws Exception {
        序列化流();
        反序列化流();


    }
}
